package ru.elteam.web.beans.session;

import ru.elteam.ejb.entities.User;

import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
import java.io.Serializable;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: Nikita.Brazhnikov
 * Date: 10/1/12
 * Time: 12:18 PM
 * To change this template use File | Settings | File Templates.
 */
@Named("users")
@SessionScoped
public class UserBean implements Serializable {

	private boolean logged = false;
    private String username;
	private String email;
	private Date lastVisit;
	private Date registerDate;
	private byte[] image;

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

	public boolean isLogged() {
		return logged;
	}

	public Date getLastVisit() {
		return lastVisit;
	}

	public void setLastVisit(Date lastVisit) {
		this.lastVisit = lastVisit;
	}

	public Date getRegisterDate() {
		return registerDate;
	}

	public void setRegisterDate(Date registerDate) {
		this.registerDate = registerDate;
	}

	public byte[] getImage() {
		return image;
	}

	public void setImage(byte[] image) {
		this.image = image;
	}

	public void setUpUser(User user) {
		this.username = user.getUsername();
		this.setLastVisit(user.getLastLoginDate());
		this.setRegisterDate(user.getRegisterDate());
		logged = true;
	}

	public void dropUser() {
		this.logged = false;
		this.username = null;
	}
}
